"""
环境模型
"""
from datetime import datetime
from sqlalchemy import Boolean, Column, DateTime, Integer, String, Text, JSON
from sqlalchemy.orm import relationship

from app.core.database import Base


class Environment(Base):
    """环境模型"""
    __tablename__ = "environments"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(50), unique=True, index=True, nullable=False)
    display_name = Column(String(100), nullable=False)
    description = Column(Text)
    env_type = Column(String(20), nullable=False)  # dev, test, staging, prod
    base_url = Column(String(500))
    docker_host = Column(String(200))
    k8s_config = Column(JSON)  # Kubernetes configuration
    registry_config = Column(JSON)  # Docker registry configuration
    resource_quotas = Column(JSON)  # Resource quotas
    network_config = Column(JSON)  # Network configuration
    monitoring_config = Column(JSON)  # Monitoring configuration
    backup_config = Column(JSON)  # Backup configuration
    is_active = Column(Boolean, default=True)
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
    
    # 关联关系
    deployments = relationship("Deployment", back_populates="environment")
